package tpo.wmb.provider.controller;

import api.order.OrderApi;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dto.Dto;
import dto.ShowWares;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pojo.BuyOrder;
import pojo.BuyReturn;
import pojo.DetailList;
import pojo.User;
import tpo.wmb.provider.service.OrderService;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController implements OrderApi  {
    @Resource
    OrderService orderService;



    //redis储存条件分页查询,每次改变了条件需要重查,无法判断什么时候需要重查,取消使用!!!!
    @Override
    public Dto<PageInfo<BuyOrder>> selectOrderList(Map<String, Object> map) {

        int pageNum = Integer.parseInt(map.get("pageNum").toString());//获得当前页码
        int pageSize = Integer.parseInt(map.get("pageSize").toString());//获得页面大小
        System.out.println("=======================" + pageNum);
        System.out.println("=======================" + pageSize);
        PageHelper.startPage(pageNum, pageSize);//开始分页,设参数
        List<BuyOrder> list = orderService.selectOrderList(map);

        PageInfo<BuyOrder> pageInfo = new PageInfo<>(list,3);//数据放入自动参数分页

        Dto<PageInfo<BuyOrder>> dto = new Dto<PageInfo<BuyOrder>>();//DTO数据传输对象
        dto.setObj(pageInfo);
        dto.setMsg("OK");
        dto.setCode(200);
        dto.setSuccess(true);
        return dto;
    }

    @Override
    public List<BuyOrder> selectOrderList2(Integer integer) {
        return orderService.selectOrderList2(integer);
    }

    @Override
    public Dto<BuyOrder> selectOrder(Integer id) {
        BuyOrder buyOrder=orderService.selectOrder(id);
        Dto<BuyOrder> dto = new Dto<BuyOrder>();//DTO数据传输对象
        dto.setObj(buyOrder);
        dto.setMsg("OK");
        dto.setCode(200);
        dto.setSuccess(true);
        return dto;
    }

    @Override
    public BuyOrder selectOrdeCoder(String s) {
        return orderService.selectOrdeCoder(s);
    }

    @Override
    public Integer updateOrder(BuyOrder buyOrder) {
        return orderService.updateOrder(buyOrder);
    }

    @Override
    public Integer updateOrder2(BuyOrder buyOrder) {
        return orderService.updateOrder2(buyOrder);
    }

    @Override
    public Integer updateOrder3(String code, BigDecimal bigDecimal) {
        return orderService.updateOrder3(code,bigDecimal);
    }

    @Override
    public Integer updateOrderState(Integer integer, Integer integer1,Integer id) {
        return orderService.updateOrderState(integer,integer1,id);
    }

    @Override
    public Integer insertOrder(BuyOrder buyOrder) {
        return orderService.insertOrder(buyOrder);
    }

    @Override
    public Integer deleteOrder(Integer id) {
        return orderService.deleteOrder(id);
    }

    @Override
    public Integer deleteOrder2(String s) {
        return null;
    }




    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++分割线---------------------------------------


    @Override
    public Dto<PageInfo<BuyReturn>> selectBuyReturnList(Map<String, Object> map) {
        int pageNum = Integer.parseInt(map.get("pageNum").toString());//获得当前页码
        int pageSize = Integer.parseInt(map.get("pageSize").toString());//获得页面大小
        PageHelper.startPage(pageNum,pageSize);
        List<BuyReturn> list = orderService.selectBuyReturnList(map);
        PageInfo<BuyReturn> pageInfo=new PageInfo<>(list,3 );

        Dto<PageInfo<BuyReturn>> dto = new Dto<>();
        dto.setObj(pageInfo);
        dto.setCode(200);
        dto.setSuccess(true);
        dto.setMsg("成功");

        return dto;
    }

    @Override
    public Dto<BuyReturn> selectBuyReturn(Integer id) {
        BuyReturn buyReturn = orderService.selectBuyReturn(id);

        Dto<BuyReturn> dto = new Dto<>();
        dto.setObj(buyReturn);
        dto.setCode(200);
        dto.setSuccess(true);
        dto.setMsg("成功");
        return dto;
    }

    @Override
    public BuyReturn selectBuyReturn2(String s) {
        return orderService.selectBuyReturn2(s);
    }

    @Override
    public Integer updateBuyReturn(BuyReturn buyReturn) {
        return orderService.updateBuyReturn(buyReturn);
    }

    @Override
    public Integer updateBuyReturn2(String s, BigDecimal bigDecimal) {
        return orderService.updateBuyReturn2(s, bigDecimal);
    }

    @Override
    public Integer updateBuyReturnState(Integer integer, Integer integer1, Integer integer2) {
        return orderService.updateBuyReturnState(integer, integer1, integer2);
    }

    @Transactional //事务管理
    @Override
    public Integer insertBuyReturn(BuyReturn buyReturn) {
        return orderService.insertBuyReturn(buyReturn);
    }

    @Override
    public Integer deleteBuyReturn(Integer id) {
        return orderService.deleteBuyReturn(id);
    }


    @Override
    public List<ShowWares> selectDetailList(String s, Integer integer) {
        return orderService.selectDetailList(s,integer);
    }

    @Override
    public List<ShowWares> selectDetailList2(String s, Integer integer) {
        return orderService.selectDetailList2(s,integer);
    }

    @Override
    public Integer insertDetailList(DetailList detailList) {
        return orderService.insertDetailList(detailList);
    }

    @Override
    public Integer updateDetailList(DetailList detailList) {
        return orderService.updateDetailList(detailList);
    }

    @Override
    public Integer deleteDetailList(Integer integer) {
        return orderService.deleteDetailList(integer);
    }


    @Override
    public Map<String, Object> seeUpdateBuyReturn(Integer id) {
        return orderService.seeUpdateBuyReturn(id);
    }

    @Override
    public Map<String, Object> detailListWares(String s) {
        return null;
    }

    @Override
    public User orderUser(Integer integer) {
        return orderService.orderUser(integer);
    }

    @Override
    public Integer updateDetailList2(List<DetailList> list) {
        return orderService.updateDetailList2(list);
    }


}
